﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domain.Rules
{
    /// <summary>
    /// 日期是否在指定的范围内
    /// </summary>
    [Serializable]
    public class DateIsInRangeRule : RuleBase
    {
        public readonly DateTime MinDate;
        public readonly DateTime MaxDate;

        // Note: Only the "largest" constructor is shown here.
        public DateIsInRangeRule(
            DateTime minDate, 
            DateTime maxDate,
            int ruleId, 
            string[] participatingLogicalFields,
            string fieldName, 
            object holder)
            : base(ruleId, participatingLogicalFields, fieldName, holder)
        {
            MinDate = minDate;
            MaxDate = maxDate;
        }

        public DateIsInRangeRule(
            DateTime minDate, 
            DateTime maxDate, 
            string fieldName, 
            object holder) : this(minDate,maxDate,0,new string[0],fieldName,holder)
        {
        }

        public override bool IsValid
        {
            get
            {
                DateTime value = (DateTime)base.GetValue();
                return (value >= MinDate && value <= MaxDate);
            }
        }
    }
}
